#include<stdio.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<unistd.h>
#include<arpa/inet.h>
#include<sys/select.h>
#include<mysql.h>
#include<string.h>

struct password
{
	char id[20];
	char passwd[20];
	int flag;
};

void sign_up(int connectfd,struct password pw)
{
    	MYSQL mysql;
    	char mysql_insert[100];
    	int rc,nflag=-1;
    	if(NULL == mysql_init(&mysql)) 
	{  
	        printf("mysql_init(): %s\n", mysql_error(&mysql));  
        	return;  
    	}  
    	if (NULL == mysql_real_connect(&mysql,  
			"localhost",  
                	"root",  
                	"root",  
                	"lts",  
                	 0,  
                	NULL,  
                	0)) 
	{  
        	printf("mysql_real_connect(): %s\n", mysql_error(&mysql));  
        	return;  
    	}  
	sprintf(mysql_insert,"INSERT INTO user (username,passwd,fd) values('%s','%s',%d)",pw.id,pw.passwd,connectfd);
	rc = mysql_query(&mysql,mysql_insert);
	if(rc==0)
	{
		nflag=1;
	}
	else
	{
		nflag=0;
	}
	send(connectfd,&nflag,sizeof(int),0);
	mysql_close(&mysql); 
}
